home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / Jotto2 src / Jotto ][ ƒ / Jotto code ƒ / jotto graphics.c < prev    next >
Text File  |  1993-12-11  |  7KB  |  319 lines

  1. /**********************************************************************\
  2.  
  3. File:        jotto globals.c
  4.  
  5. Purpose:    This module handles Jotto-specific graphics (drawing to
  6.             offscreen & onscreen bitmaps).
  7.  
  8.  
  9. Jotto ][ -=- a simple word game, revisited
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "jotto globals.h"
  30. #include "jotto graphics.h"
  31. #include "msg graphics.h"
  32. #include "msg environment.h"
  33. #include "util.h"
  34.  
  35. CIconHandle        gColorIcons[3];
  36. Handle            gBWIcons[3];
  37. PicHandle        gBackgroundPict;
  38.  
  39. void DrawBoardColor()
  40. {
  41.     RGBColor        oldForeColor, oldBackColor;
  42.     GrafPtr            curPort;
  43.     Rect            theRect;
  44.     int                i;
  45.     Str255            tempStr;
  46.     char            oldChar;
  47.     int                endi;
  48.     unsigned char    *temp="\pYOU ARE A";
  49.     unsigned char    *temp2="\pWINNER!";
  50.     unsigned char    *temp3="\pClick the mouse button to continue";
  51.     PicHandle        thePic;
  52.     
  53.     GetForeColor(&oldForeColor);
  54.     GetBackColor(&oldBackColor);
  55.     
  56.     GetPort(&curPort);
  57.     
  58.     if (!gIsEndGame)
  59.         DrawPicture(gBackgroundPict, &(curPort->portRect));
  60.     else
  61.     {
  62.         thePic=GetPicture(134);
  63.         FillRect(&(curPort->portRect), black);
  64.         TextFont(144);
  65.         TextSize(24);
  66.         TextMode(srcXor);
  67.         MoveTo(150-StringWidth(temp)/2, 140);
  68.         DrawString(temp);
  69.         SetRect(&theRect, 0, 150, 300, 220);
  70.         DrawPicture(thePic, &theRect);
  71.         MoveTo(150-StringWidth(temp2)/2, 250);
  72.         DrawString(temp2);
  73.         TextFont(geneva);
  74.         TextSize(9);
  75.         MoveTo(150-StringWidth(temp3)/2, 290);
  76.         DrawString(temp3);
  77.         ReleaseResource(thePic);
  78.     }    
  79.     DrawCurrentWord();
  80.     
  81.     if (!gIsEndGame)
  82.     {
  83.         if (gInProgress)
  84.             HighlightChar();
  85.         
  86.         endi=(gInProgress) ? gNumTries : (gNumTries==MAX_TRIES) ? gNumTries : gNumTries+1;
  87.         for (i=0; i<endi; i++)
  88.         {
  89.             MoveTo(20+gWindowWidth/2-4*CharWidth(' '),105+i*12);
  90.             Mymemcpy((Ptr)((long)tempStr+1), gHumanWord[i], gNumLetters);
  91.             tempStr[0]=gNumLetters;
  92.             DrawString(tempStr);
  93.             DrawString("\p    ");
  94.             NumToString(gNumRight[i], tempStr);
  95.             DrawChar(tempStr[1]);
  96.         }
  97.     
  98.         theRect.top=90;
  99.         theRect.bottom=122;
  100.         theRect.left=43;
  101.         theRect.right=theRect.left+32;
  102.         for (i=0; i<3; i++)
  103.         {
  104.             PlotCIcon(&theRect, gColorIcons[i]);
  105.             theRect.top+=35;
  106.             theRect.bottom+=35;
  107.         }
  108.         PlotCIcon(&theRect, gColorIcons[2]);
  109.         theRect.top+=35;
  110.         theRect.bottom+=35;
  111.         PlotCIcon(&theRect, gColorIcons[1]);
  112.         
  113.         oldChar=gWhichChar;
  114.         gWhichChar=0x0a;
  115.         DrawOneChar();
  116.         gWhichChar=oldChar;
  117.     }
  118.     
  119.     RGBForeColor(&oldForeColor);
  120.     RGBBackColor(&oldBackColor);
  121. }
  122.  
  123. void DrawBoardBW()
  124. {
  125.     int                i;
  126.     GrafPtr            curPort;
  127.     Rect            theRect;
  128.     Str255            tempStr;
  129.     char            oldChar;
  130.     int                endi;
  131.     unsigned char    *temp="\pYOU ARE A";
  132.     unsigned char    *temp2="\pWINNER!";
  133.     unsigned char    *temp3="\pClick the mouse button to continue";
  134.     PicHandle        thePic;
  135.     
  136.     GetPort(&curPort);
  137.     
  138.     if (!gIsEndGame)
  139.         DrawPicture(gBackgroundPict, &(curPort->portRect));
  140.     else
  141.     {
  142.         FillRect(&(curPort->portRect), black);
  143.         thePic=GetPicture(135);
  144.         FillRect(&(curPort->portRect), black);
  145.         TextFont(144);
  146.         TextSize(24);
  147.         TextMode(srcXor);
  148.         MoveTo(150-StringWidth(temp)/2, 140);
  149.         DrawString(temp);
  150.         SetRect(&theRect, 0, 150, 300, 220);
  151.         DrawPicture(thePic, &theRect);
  152.         MoveTo(150-StringWidth(temp2)/2, 250);
  153.         DrawString(temp2);
  154.         TextFont(geneva);
  155.         TextSize(9);
  156.         MoveTo(150-StringWidth(temp3)/2, 290);
  157.         DrawString(temp3);
  158.         ReleaseResource(thePic);
  159.     }
  160.         
  161.     DrawCurrentWord();
  162.     
  163.     if (!gIsEndGame)
  164.     {
  165.         if (gInProgress)
  166.             HighlightChar();
  167.         
  168.         endi=(gInProgress) ? gNumTries : (gNumTries==MAX_TRIES) ? gNumTries : gNumTries+1;
  169.         for (i=0; i<endi; i++)
  170.         {
  171.             MoveTo(20+gWindowWidth/2-4*CharWidth(' '),105+i*12);
  172.             Mymemcpy((Ptr)((long)tempStr+1), gHumanWord[i], gNumLetters);
  173.             tempStr[0]=gNumLetters;
  174.             DrawString(tempStr);
  175.             DrawString("\p    ");
  176.             NumToString(gNumRight[i], tempStr);
  177.             DrawChar(tempStr[1]);
  178.         }
  179.     
  180.         theRect.top=90;
  181.         theRect.bottom=122;
  182.         theRect.left=43;
  183.         theRect.right=theRect.left+32;
  184.         for (i=0; i<3; i++)
  185.         {
  186.             PlotIcon(&theRect, gBWIcons[i]);
  187.             theRect.top+=35;
  188.             theRect.bottom+=35;
  189.         }
  190.         PlotIcon(&theRect, gBWIcons[2]);
  191.         theRect.top+=35;
  192.         theRect.bottom+=35;
  193.         PlotIcon(&theRect, gBWIcons[1]);
  194.         
  195.         oldChar=gWhichChar;
  196.         gWhichChar=0x0a;
  197.         DrawOneChar();
  198.         gWhichChar=oldChar;
  199.     }
  200. }
  201.  
  202. void DrawWordInList(void)
  203. {
  204.     int            i;
  205.     Str255        tempStr;
  206.     GrafPtr        curPort;
  207.     
  208.     GetPort(&curPort);
  209.     SetPort(gMainWindow);
  210.     
  211.     TextFont(monaco);
  212.     TextSize(9);
  213.     
  214.     MoveTo(20+gWindowWidth/2-4*CharWidth(' '),105+gNumTries*12);
  215.     Mymemcpy((Ptr)((long)tempStr+1), gHumanWord[gNumTries], gNumLetters);
  216.     tempStr[0]=gNumLetters;
  217.     DrawString(tempStr);
  218.     DrawString("\p    ");
  219.     NumToString(gNumRight[gNumTries], tempStr);
  220.     DrawChar(tempStr[1]);
  221.     
  222.     SetPort(curPort);
  223. }
  224.  
  225. void DrawOneChar(void)
  226. {
  227.     Rect            theRect;
  228.     char            thisChar;
  229.     GrafPtr            curPort;
  230.     
  231.     GetPort(&curPort);    
  232.     SetPort(gMainWindow);
  233.     TextFont(144);
  234.     TextSize(24);
  235.     TextMode(srcXor);
  236.     theRect.top=32;
  237.     theRect.bottom=theRect.top+36;
  238.     theRect.left=gWindowWidth/2-98-((gNumLetters==6) ? 20 : 0)+40*gWhichChar;
  239.     theRect.right=theRect.left+36;
  240.     FillRect(&theRect, black);
  241.     thisChar=gHumanWord[gNumTries][gWhichChar];
  242.     MoveTo(gWindowWidth/2-80-((gNumLetters==6) ? 20 : 0)+gWhichChar*40-CharWidth(thisChar)/2,
  243.         (thisChar=='Q') ? 59 : 61);
  244.     DrawChar(thisChar);
  245.     SetPort(curPort);
  246. }
  247.  
  248. void DrawCurrentWord(void)
  249. {
  250.     int            i;
  251.     Rect        theRect;
  252.     char        thisChar;
  253.     
  254.     TextFont(144);
  255.     TextSize(24);
  256.     TextMode(srcXor);
  257.     theRect.top=31;
  258.     theRect.bottom=theRect.top+38;
  259.     theRect.left=gWindowWidth/2-99-((gNumLetters==6) ? 20 : 0);
  260.     theRect.right=theRect.left+38;
  261.     for (i=0; i<gNumLetters; i++)
  262.     {
  263.         FillRect(&theRect, black);
  264.         ForeColor(whiteColor);
  265.         FrameRect(&theRect);
  266.         ForeColor(blackColor);
  267.         theRect.left+=40;
  268.         theRect.right+=40;
  269.     }
  270.     
  271.     for (i=0; i<gNumLetters; i++)
  272.     {
  273.         thisChar=gHumanWord[gNumTries][i];
  274.         MoveTo(gWindowWidth/2-80-((gNumLetters==6) ? 20 : 0)+i*40-CharWidth(thisChar)/2,
  275.             (thisChar=='Q') ? 59 : 61);
  276.         DrawChar(thisChar);
  277.     }
  278.     TextFont(monaco);
  279.     TextSize(9);
  280. }
  281.  
  282. void HighlightChar(void)
  283. {
  284.     Rect            theRect;
  285.     
  286.     theRect.top=32;
  287.     theRect.bottom=theRect.top+36;
  288.     theRect.left=gWindowWidth/2-98-((gNumLetters==6) ? 20 : 0)+40*gWhichChar;
  289.     theRect.right=theRect.left+36;
  290.     InvertRect(&theRect);
  291. }
  292.  
  293. void InitJottoGraphics(void)
  294. {
  295.     int                i;
  296.     
  297.     for (i=0; i<3; i++)
  298.     {
  299.         if (gHasColorQD)
  300.             gColorIcons[i]=GetCIcon(128+i);
  301.         gBWIcons[i]=GetIcon(128+i);
  302.     }
  303.     gBackgroundPict=GetPicture(200);    
  304. }
  305.  
  306. void ShutdownJottoGraphics(void)
  307. {
  308.     int            i;
  309.     
  310.     for (i=0; i<3; i++)
  311.     {
  312.         if (gHasColorQD)
  313.             DisposeCIcon(gColorIcons[i]);
  314.         ReleaseResource(gBWIcons[i]);
  315.     }
  316.  
  317.     ReleaseResource(gBackgroundPict);
  318. }
  319.